//
//  PELocalEnergyStatisticsChartView.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/4/8.
//

#import "RHLocalEnergyChartView.h"
#import "DeviceChartItemView.h"
#import "DevChartModel.h"
#import "DeviceChartFieldModel.h"
#import "QMUILabel+LHAdd.h"
#import "RHLocalEnergyMaskView.h"
#import "RHLeftAxisFormatter.h"
#import "RHRightAxisFormatter.h"

@interface RHLocalEnergyChartView()
@property (nonatomic ,copy) NSArray *colorList;


//左边Y轴单位
@property (nonatomic, strong) QMUILabel *leftUnitLab;
//右边Y轴单位
@property (nonatomic, strong) QMUILabel *rightUnitLab;

//气泡
@property (nonatomic, strong) RHLocalEnergyMaskView *maskView;
/// 图表
@property (nonatomic, strong) LineChartView *lineChartView;

@property (nonatomic, assign) NSInteger selectIndex;

@property (nonatomic, strong) UIView *scrollBgView;

@property (nonatomic, strong) UIScrollView *scroll;

@property (nonatomic, strong) UIView *contentView;

@property (nonatomic, strong) NSMutableArray *itemsArray;

@property (nonatomic, strong) NSMutableArray *unitArr;

@end
@implementation RHLocalEnergyChartView

- (instancetype)initWithFrame:(CGRect)frame type:(NSInteger)type{
    self = [super initWithFrame:frame];
    if (self) {
        self.colorList = @[@"#FFCE00",@"#678EF2",@"#10E2FF",@"#B36DFA",@"#98D767",@"FB6085",@"8956F8"];
        [self setupUI];
        
    }
    return self;
}


- (void)setChartModel:(DevChartModel *)chartModel{
    _chartModel = chartModel;
    self.selectIndex = _chartModel.timeType;
    [self setChartData];
    NSString *timeStr;
    if (_chartModel.timeType == TimeType_Day) {
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:[_chartModel.curTime integerValue]];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateStyle:NSDateFormatterMediumStyle];
        [formatter setTimeStyle:NSDateFormatterShortStyle];
        [formatter setDateFormat:@"YYYY-MM-dd"];
        NSString *dateTime = [formatter stringFromDate:date];
        timeStr = dateTime;
      
    }else if (_chartModel.timeType == TimeType_Month) {
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:[_chartModel.curTime integerValue]];
        timeStr = [NSString stringWithFormat:@"%02ld-%02ld",[date year],[date month]];
      
    }else if (_chartModel.timeType == TimeType_Year){
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:[_chartModel.curTime integerValue]];
        timeStr = [NSString stringWithFormat:@"%ld",[date year]];
      
    }else{
        timeStr = @"";
    }

    
    
    __block CGFloat total_width = 0;
    kWeakSelf;
    [self.itemsArray enumerateObjectsUsingBlock:^(DeviceChartItemView  *_Nonnull itemView, NSUInteger idx, BOOL * _Nonnull stop) {
        CGFloat item_width = 0;
        DeviceChartFieldModel *model;
        if (idx<self.chartModel.selectArray.count) {
            model = self.chartModel.selectArray[idx];
            model.colorStr = self.colorList[idx];
            [itemView setModel:model];
            NSAttributedString *attr = [[NSAttributedString alloc] initWithString:model.alias.rh_localized];
            CGSize size = [itemView.conentLab getLableSizeWithAttStr:attr maxHeight:15];
            item_width = size.width+25;
            [itemView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(item_width);
            }];
            [itemView setHidden:NO];
            total_width = total_width+item_width+5;
        }else{
            [itemView setHidden:NO];
            [itemView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(0);
            }];
        }
        
        [self.scrollBgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(MIN(self.frame.size.width,total_width+5));
        }];
    
        itemView.selectBlock = ^BOOL(DeviceChartFieldModel * _Nonnull model) {
            model.isShowLine = !model.isShowLine;
            [weakSelf.chartModel updateyAxisArray];
            [weakSelf setChartData];
            return YES;
        };
    }];

}

-(void)setChartData
{
    [self.lineChartView clear];
    self.leftUnitLab.hidden = YES;
    //X轴要显示的数据
    self.lineChartView.xAxis.valueFormatter = [[ChartIndexAxisValueFormatter alloc]initWithValues:self.chartModel.xTitlesArray];
    NSInteger labelCount = 10;
    if(kUI_WINDOW_H <=667){
        labelCount = 8;
    }
//    [self.lineChartView.xAxis setLabelCount:8 force:YES] ;//强制设置x轴显示的个数
    //横屏显示多几个
    if(self.chartModel.xTitlesArray.count < labelCount){
        labelCount = self.chartModel.xTitlesArray.count;
    }
    [self.lineChartView.xAxis setLabelCount:labelCount force:NO];//设置x轴显示的个数
    self.lineChartView.xAxis.axisMaxLabels = labelCount;
    self.lineChartView.xAxis.axisMinLabels = labelCount;
    self.lineChartView.xAxis.granularity = 1;
    [self.unitArr removeAllObjects];
    kWeakSelf;
    __block CGFloat left_y_max = 0;
    __block CGFloat right_y_max = 0;
    NSMutableArray *dataSets = [[NSMutableArray alloc] init];
    [self.chartModel.selectArray enumerateObjectsUsingBlock:^(DeviceChartFieldModel  *_Nonnull model, NSUInteger idx, BOOL * _Nonnull stop) {
     
        if(model.isShowLine){
            LineChartDataSet *set = [weakSelf createDataSetWithModel:model linecolor:weakSelf.colorList[idx]];
            //单位
            if(![weakSelf.unitArr containsObject:model.unitName]){
                [weakSelf.unitArr addObject:ValidNullDataToString(model.unitName, @"--")];
            }
            //数据对应 左边Y轴 还是 右边Y轴
            if(weakSelf.unitArr.count<2){
                set.axisDependency = AxisDependencyLeft;
                left_y_max = MAX(model.value_max, left_y_max);
                self.leftUnitLab.text = model.unitName;
                self.leftUnitLab.hidden = NO;
                self.rightUnitLab.hidden = YES;
            }else{
                //两个单位
                if([model.unitName isEqualToString:weakSelf.unitArr[0]]){
                    set.axisDependency = AxisDependencyLeft;
                    left_y_max = MAX(model.value_max, left_y_max);
                }else{
                    set.axisDependency = AxisDependencyRight;
                    right_y_max = MAX(model.value_max, right_y_max);
                    self.rightUnitLab.text = model.unitName;
                    self.rightUnitLab.hidden = NO;
                }
                
                self.lineChartView.rightAxis.enabled = YES;
            }
            
            [dataSets addObject:set];
            
        }
        
    }];
//    self.lineChartView.leftAxis.axisMaximum = 100 ;
//    self.lineChartView.rightAxis.axisMaximum = 100;
    //没有数据的时候也展示
    if(left_y_max == 0)
    {
        left_y_max = 100;
    }
    if(right_y_max == 0){
        right_y_max = 100;
    }
    
    //创建 LineChartData 对象, 此对象就是lineChartView需要最终数据对象
    LineChartData *lineData = [[LineChartData alloc] initWithDataSets:dataSets];
    self.lineChartView.data = lineData;
    //这里可以调用一个加载动画即1s出来一个绘制点
//    [self.lineChartView animateWithXAxisDuration:0.2f];
   
    //通知data去更新
    [self.lineChartView.data notifyDataChanged];
    //通知图表去更新
    [self.lineChartView notifyDataSetChanged];
}

#pragma mark ----- 创建曲线
-(LineChartDataSet*)createDataSetWithModel:(DeviceChartFieldModel*)model linecolor:(NSString*)colorStr;
{
    NSMutableArray *entryArr = [[NSMutableArray alloc]init];
    
    [self.chartModel.xTitlesArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        ChartDataEntry *entry = [[ChartDataEntry alloc] initWithX:idx y:[model.dataArray[idx] floatValue]];
        [entryArr addObject:entry];
    }];
    
    LineChartDataSet *set = [[LineChartDataSet alloc] initWithEntries:entryArr label:model.keyName];
    [set setColor:kCOLOR_HEX(colorStr)];//折线颜色
    //set1.lineDashLengths = @[@4.0,@2.0];//设置虚线各段长度
    set.mode = LineChartModeHorizontalBezier;//曲线平滑显示   贝塞尔曲线
    
    set.drawIconsEnabled = YES;//是否绘制图标
    set.formLineWidth = 1.1;//图例的线宽
    set.formSize = 8.0;//图例的字体大小
    set.lineWidth = 2.0;//折线的宽度
    

    set.drawCirclesEnabled = NO;//是否绘制拐点
    set.drawCircleHoleEnabled = YES;//是否画空心圆
    set.circleColors = @[kCOLOR_HEX(colorStr)];//外圆颜色
    set.circleHoleColor = UIColor.whiteColor; //内圆颜色
    set.circleRadius = 2; //外圆半径
    set.circleHoleRadius = 1; //内圆半径
    
    set.drawValuesEnabled = NO;//是否在拐点处显示数据
    set.valueColors = @[kCOLOR_HEX(colorStr)];//拐点上的文字颜色
    set.valueFont = [UIFont systemFontOfSize:8];//拐点上的文字大小
    
    //折线拐点样式
    //第二种填充样式:渐变填充
    set.drawFilledEnabled = YES;//是否填充颜色
    NSArray *gradientColors = @[(id)[UIColor colorWithHexString:colorStr alpha:0.15].CGColor,
                                (id)[UIColor colorWithHexString:colorStr alpha:0.0].CGColor];
    CGGradientRef gradientRef = CGGradientCreateWithColors(nil, (CFArrayRef)gradientColors, nil);
    set.fillAlpha = 1.0f;//透明度
    set.fill = [[ChartLinearGradientFill alloc]initWithGradient:gradientRef angle:-90.0f];//赋值填充颜色对象
    CGGradientRelease(gradientRef);//释放gradientRef
    
    //点击选中拐点的交互样式
    set.highlightEnabled = YES;//选中拐点,是否开启高亮效果(显示十字线)
//    set.drawVerticalHighlightIndicatorEnabled = NO; //不显示纵向十字线
    set.drawHorizontalHighlightIndicatorEnabled = NO; //不显示横向十字线
    set.highlightColor = kRGB(23,23,23);//点击选中拐点的十字线的颜色
    set.highlightLineWidth = 1.1/[UIScreen mainScreen].scale;//十字线宽度
    set.highlightLineDashLengths = @[@5, @5];//十字线的虚线样式
    
    return set;
}

- (void)setupUI{
    [self setBackgroundColor:UIColor.whiteColor];
    UIView *itemBgView = [[UIView alloc] init];
    [itemBgView setBackgroundColor:UIColor.whiteColor];
    [self addSubview:itemBgView];
    
    kWeakSelf;
    
    

    [self addSubview:self.lineChartView];
    
    //添加单位
    QMUILabel *leftUnitLab = [[QMUILabel alloc]init];
    leftUnitLab.textColor = UIColor.lightGrayColor;
    leftUnitLab.font = [UIFont systemFontOfSize:13];
    [self addSubview:leftUnitLab];
    self.leftUnitLab = leftUnitLab;
    
    QMUILabel *rightUnitLab = [[QMUILabel alloc]init];
    rightUnitLab.textColor = UIColor.lightGrayColor;
    rightUnitLab.font = [UIFont systemFontOfSize:13];
    [self addSubview:rightUnitLab];
    self.rightUnitLab = rightUnitLab;
    
    [leftUnitLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.lineChartView).offset(5);
        make.bottom.equalTo(weakSelf.lineChartView.mas_top);
    }];
    
    [rightUnitLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.lineChartView).offset(-5);
        make.bottom.equalTo(weakSelf.lineChartView.mas_top);
    }];
    
    //下面的曲线标签按钮
    _scrollBgView = [[UIView alloc] init];
    [_scrollBgView setBackgroundColor:UIColor.orangeColor];
    [self addSubview:_scrollBgView];
    
    _scroll = [[UIScrollView alloc] init];
    [_scroll setShowsHorizontalScrollIndicator:NO];
    _scroll.backgroundColor = [UIColor whiteColor];
    [_scrollBgView addSubview:_scroll];
    
    _contentView = [[UIView alloc] init];
    _contentView.backgroundColor = [UIColor whiteColor];
    [_scroll addSubview:_contentView];
    
    __block DeviceChartItemView *lastItem;
    __block CGFloat width = 5;
    [self.colorList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        DeviceChartItemView *itemView = [[DeviceChartItemView alloc] init];
        [itemView.markLab.layer setBorderColor:FontColor(obj).CGColor];
//        [itemView shadow:UIColor.blackColor opacity:0.1 radius:5 offset:CGSizeMake(0, 1)];
        [_contentView addSubview:itemView];
        [self.itemsArray addObject:itemView];

        if (!lastItem) {
            [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_offset(width);
                make.top.mas_offset(5);
                make.centerY.mas_offset(0);
                make.height.mas_equalTo(20);
                make.width.mas_equalTo(0);
            }];
            width = width;
        }else{
            [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(lastItem.mas_right).offset(5);
                make.top.mas_offset(5);
                make.centerY.mas_offset(0);
                make.height.mas_equalTo(20);
                make.width.mas_equalTo(0);
            }];
            width = width+5;
        }
        lastItem = itemView;
    }];
    
    [lastItem mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(0);
    }];
    
    
    [self.scrollBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_offset(0);
        make.top.equalTo(self.lineChartView.mas_bottom).offset(0);
        make.bottom.mas_offset(-10);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(MIN(self.frame.size.width,width));
    }];
    
    
    [_scroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
        make.width.greaterThanOrEqualTo(@0.f);//此处保证容器View高度的动态变化 大于等于0.f的高度
    }];
  
    
    
    [self.lineChartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.mas_offset(0);
       
    }];
   
    
   
    
   
   
}






- (LineChartView *)lineChartView{
    if (!_lineChartView) {
        _lineChartView = [[LineChartView alloc]init];
        _lineChartView.delegate = self;
       
        _lineChartView.chartDescription.enabled = NO;  //是否显示描述label
        _lineChartView.extraRightOffset = 0;//右边缩进
        _lineChartView.extraBottomOffset = 0;//图表底部缩进,也就是与图例的距离
        _lineChartView.backgroundColor = kRGB(255, 255, 255);

        _lineChartView.noDataText = @"加载中...";//没有数据时显示的文字
       
        _lineChartView.legend.enabled = NO;//是否显示说明图标
        _lineChartView.legend.form = ChartLegendFormSquare;//说明图例的样式
        _lineChartView.legend.formSize = 3;//图例大小（头部）
        _lineChartView.legend.formToTextSpace = 5;//图例与文字的距离
        _lineChartView.legend.yOffset = 10;//图例与底部的距离
        _lineChartView.legend.xEntrySpace = 20;//图例与图例之间的距离
        _lineChartView.legend.neededHeight = 50;
        _lineChartView.legend.stackSpace = 10;
        _lineChartView.dragEnabled = YES; //拖动手势
        _lineChartView.dragDecelerationEnabled = YES;//拖拽后是否有惯性效果
        _lineChartView.dragDecelerationFrictionCoef = 0.9;//拖拽后惯性效果的摩擦系数(0~1)，数值越小，惯性越不明显
        _lineChartView.pinchZoomEnabled = YES; //捏合手势
        _lineChartView.rightAxis.enabled = YES;  //隐藏右Y轴
        _lineChartView.doubleTapToZoomEnabled = YES;  //禁止双击缩放
        _lineChartView.drawGridBackgroundEnabled = NO; //绘制图形区域背景
        _lineChartView.drawBordersEnabled = NO; //绘制图形区域边框
        _lineChartView.dragEnabled = YES; //拖动气泡
        _lineChartView.scaleYEnabled = NO;//Y轴不允许缩放
        _lineChartView.scaleXEnabled = YES;//Y轴不允许缩放

    //    [self.LineChartView setVisibleXRangeMaximum:5];// 最大显示区域
    //    [self.LineChartView setVisibleXRangeMinimum:1];// 最小显示区域
        //气泡标签
        _lineChartView.drawMarkers = YES;
        
        ChartMarkerView *marker = [[ChartMarkerView alloc]
                                 init];
        marker.offset = CGPointZero;
        marker.chartView = _lineChartView;
//        marker.minimumSize = CGSizeMake(60.f, 20.f);
//        marker.image = [UIImage imageNamed:@""];
        
        RHLocalEnergyMaskView *maskView = [[RHLocalEnergyMaskView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
        [marker addSubview:maskView];
        self.maskView = maskView;
        _lineChartView.marker = marker;

       
        //只滑动不缩放
    //    ChartViewPortHandler *scalX = self.LineChartView.viewPortHandler;
    //    [scalX setMinimumScaleX:1.01];
        
        
        //设置左Y轴
        ChartYAxis *leftAxis =_lineChartView.leftAxis;
        leftAxis.labelPosition = YAxisLabelPositionOutsideChart;//label位置
        leftAxis.axisLineWidth = 1;
        leftAxis.axisMaxLabels = 6;     //y轴展示多少个
        leftAxis.labelFont = [UIFont systemFontOfSize:12];
        leftAxis.labelTextColor = UIColor.lightGrayColor; //文本颜色
        leftAxis.axisLineColor = kRGB(217, 217, 217);    //左Y轴线条颜色
        leftAxis.gridLineDashLengths = @[@3.0f, @3.0f];//设置虚线样式的网格线
        leftAxis.gridColor = [UIColor colorWithRed:200/255.0f green:200/255.0f blue:200/255.0f alpha:1];//网格线颜色
        leftAxis.gridAntialiasEnabled = YES;//开启抗锯齿
        leftAxis.zeroLineColor = [UIColor redColor];    //左Y轴底线条颜色
        leftAxis.drawZeroLineEnabled = NO;//绘制0线
        leftAxis.valueFormatter = [[RHLeftAxisFormatter alloc]initWithUnitArr:self.unitArr];
        leftAxis.axisMinimum = 0;//Y轴最小值
//        leftAxis.axisMaximum = 150;   //Y轴最大值
        leftAxis.drawAxisLineEnabled = NO;

        
        //设置 右-->Y轴
        ChartYAxis *rightAxis =_lineChartView.rightAxis;
        rightAxis.labelPosition = YAxisLabelPositionOutsideChart;//label位置
        rightAxis.axisLineWidth = 1;
        rightAxis.axisMaxLabels = 6;     //y轴展示多少个
        rightAxis.labelFont = [UIFont systemFontOfSize:12];
        rightAxis.labelTextColor = UIColor.lightGrayColor; //文本颜色
        rightAxis.axisLineColor = kRGB(217, 217, 217);    //左Y轴线条颜色
        rightAxis.gridLineDashLengths = @[@3.0f, @3.0f];//设置虚线样式的网格线
        rightAxis.gridColor = [UIColor colorWithRed:200/255.0f green:200/255.0f blue:200/255.0f alpha:1];//网格线颜色
        rightAxis.gridAntialiasEnabled = YES;//开启抗锯齿
        rightAxis.zeroLineColor = [UIColor redColor];    //左Y轴底线条颜色
        rightAxis.drawZeroLineEnabled = NO;//绘制0线
        rightAxis.valueFormatter = [[RHRightAxisFormatter alloc]initWithUnitArr:self.unitArr];
        rightAxis.axisMinimum = 0;//Y轴最小值
//        rightAxis.axisMaximum = 150;   //Y轴最大值
        rightAxis.drawAxisLineEnabled = NO;
        
        
        // 设置X轴
        ChartXAxis *xAxis =_lineChartView.xAxis;
        xAxis.axisLineWidth = 1.0/[UIScreen mainScreen].scale;//设置X轴线宽
        xAxis.axisLineColor = UIColor.lightGrayColor;
        xAxis.labelPosition =XAxisLabelPositionBottom; //x轴文字的位置
        xAxis.labelFont = [UIFont systemFontOfSize:12];//文字字体
        xAxis.labelTextColor = UIColor.lightGrayColor;//文字颜色
    //    xAxis.labelCount = 5;
//        xAxis.axisMaxLabels = 10;//x轴最多显示个数;
//        xAxis.axisMinLabels = 2;//x轴最少显示个数;
//        xAxis.granularity = 2;/*x轴标题中间最小的间隔。

        xAxis.drawAxisLineEnabled = YES;//是否画x轴线
        xAxis.avoidFirstLastClippingEnabled = NO;//避免文字显示不全 这个属性很重要
        
        xAxis.drawGridLinesEnabled = NO;//是否画网格
        xAxis.gridColor = UIColor.redColor;//x轴对应网格线的颜色
        xAxis.gridLineWidth = 1;//x轴对应网格线的大小
        xAxis.gridLineDashLengths = @[@4,@2];  //虚线各段长度
    //    xAxis.labelRotationAngle = -30.0;//设置文字旋转角度
       

        //自定义数据显示格式
    //     NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    //    [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
    //    [formatter setPositiveFormat:@"#0.0"];
    //    formatter.positivePrefix = @"#";
    //    xAxis.valueFormatter = [[ChartDefaultAxisValueFormatter alloc]initWithFormatter:formatter];
        
        
        //加载动画时长
        [_lineChartView animateWithYAxisDuration:0.2 easingOption:ChartEasingOptionEaseInBack];
    }
    return _lineChartView;
}

#pragma mark --------------------chartView delegate ------------------
#pragma mark 图表中数值被选中
-(void)chartValueSelected:(ChartViewBase *)chartView entry:(ChartDataEntry *)entry highlight:(ChartHighlight *)highlight{
    
    [self.maskView updateModel:self.chartModel index:(NSInteger)highlight.x colors:self.colorList];
    
    ChartMarkerView *makerView = (ChartMarkerView*)chartView.marker;
    CGFloat off_x = 0;
    if(chartView.width - highlight.xPx < self.maskView.width)
    {
        off_x = -self.maskView.width;
    }else if (highlight.xPx < self.maskView.width/2){
        off_x = 0;
    }else{
        off_x = -self.maskView.width/2;
    }
    
    CGFloat off_y = 0;
    if(chartView.height - highlight.yPx < self.maskView.height)
    {
        off_y = -self.maskView.height;
    }else if (highlight.yPx < self.maskView.height/2){
        off_y = 0;
    }else{
        off_y = -self.maskView.height/2;
    }
    
    
    makerView.offset = CGPointMake(off_x, off_y);
    
    
    
    
}

#pragma mark 图表中的空白区域被选中
-(void)chartValueNothingSelected:(ChartViewBase *)chartView{
    NSLog(@"空白区域被选中");
}

#pragma mark 图表被缩放
-(void)chartScaled:(ChartViewBase *)chartView scaleX:(CGFloat)scaleX scaleY:(CGFloat)scaleY{
//    NSLog(@"图表被缩放");
    //根据缩放调整显示间隔
//    if(scaleX>=3){
//        self.lineChartView.xAxis.granularity = 1;
//    }else if(scaleX>=2){
//        self.lineChartView.xAxis.granularity = 2;
//    }
//    chartView.xAxis.granularity = self.chartModel.xTitlesArray.count/8*scaleX;
    NSLog(@"------>图表缩放倍数:%f",scaleX);
    
//    NSString *time = @"23:23";
//    CGFloat width = [time getStringWidthFont:self.lineChartView.xAxis.labelFont limitHeight:25];
//    NSLog(@"----->333%@",chartView.xAxis.yy_modelDescription);
    
}

#pragma mark 图表被移动
-(void)chartTranslated:(ChartViewBase *)chartView dX:(CGFloat)dX dY:(CGFloat)dY{
//    NSLog(@"图表被移动");
}


#pragma mark ------ lazy load

- (NSMutableArray *)itemsArray{
    if (!_itemsArray) {
        _itemsArray = [NSMutableArray array];
    }
    return _itemsArray;
}

-(NSMutableArray *)unitArr
{
    if(!_unitArr)
    {
        _unitArr = [NSMutableArray array];
    }
    return _unitArr;;
}

@end
